package com.gigi.controller;

import com.alibaba.cola.dto.MultiResponse;
import com.alibaba.cola.dto.Response;
import com.alibaba.cola.dto.SingleResponse;
import com.gigi.common.PageRequest;
import com.gigi.entity.UserEntity;
import com.gigi.model.dto.UserDTO;
import com.gigi.model.request.ListUserRequest;
import com.gigi.model.request.LoginRequest;
import com.gigi.model.request.RegisterRequest;
import com.gigi.model.request.SearchUsersRequest;
import com.gigi.service.manual.UserManageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@Api(tags = "用户管理")
@RestController
@RequestMapping("user-manage")
public class UserManageController {

    @Autowired
    private UserManageService userManageService;

    @ApiOperation(value = "注册")
    @PostMapping("register")
    public Response register(@RequestBody @Validated RegisterRequest request) {
        return userManageService.register(request);
    }

    @ApiOperation(value = "登录")
    @PostMapping("login")
    public Response login(@RequestBody @Validated LoginRequest request, HttpServletRequest httpServletRequest) {
        return userManageService.login(request, httpServletRequest);
    }

    @ApiOperation(value = "获取当前用户")
    @GetMapping("currentUser")
    public SingleResponse<UserEntity> currentUser(HttpServletRequest httpServletRequest) {
        return userManageService.currentUser(httpServletRequest);
    }

    @ApiOperation(value = "注销")
    @PostMapping("outLogin")
    public Response outLogin(HttpServletRequest httpServletRequest) {
        return userManageService.outLogin(httpServletRequest);
    }

    @ApiOperation(value = "列表")
    @PostMapping("list")
    public MultiResponse<UserEntity> list(@RequestBody ListUserRequest request, HttpServletRequest httpServletRequest) {
        return userManageService.list(request, httpServletRequest);
    }

    @ApiOperation(value = "根据标签搜索用户")
    @PostMapping("search")
    public MultiResponse<UserEntity> searchUserByTags(@RequestBody @Validated SearchUsersRequest request,
                                                      HttpServletRequest httpServletRequest) {
        return userManageService.searchUserByTags(request, httpServletRequest);
    }

    @ApiOperation(value = "编辑用户信息")
    @PostMapping("editInfo")
    public Response editInfo(@RequestBody @Validated UserDTO request, HttpServletRequest httpServletRequest) {
        return userManageService.editInfo(request, httpServletRequest);
    }

    @ApiOperation(value = "推荐")
    @PostMapping("recommend")
    public MultiResponse<UserEntity> recommend(@RequestBody PageRequest request, HttpServletRequest httpServletRequest) {
        return userManageService.recommend(request, httpServletRequest);
    }

}
